# -*- coding: utf-8 -*-
# @Time : 2019/1/10 17:28
# @Author : Administrator
# @File : woniuboss_login.py
# @Project : python
# @title : login_test

import  requests,unittest
from python42.test_woniuboss.csv_read import Data_Read
from HTMLTestRunner import HTMLTestRunner


class WoniuBoss_Login(unittest.TestCase):
    def setUp(self):
        self.data = Data_Read()
        self.list = self.data.read_csv("data.csv")
    def test001(self):
        username = self.list[0]["username"]
        password = self.list[0]["password"]
        expect = self.list[0]["expect"]
        ses=requests.session()
        result=ses.post(url="http://192.168.2.193:8080/woniuboss2.5/log/userLogin" ,
                 data={"userName":username,"userPass":password,"checkcode":"0000"},)
        actual=result.text
        print(actual)
        print(expect)
        assert expect == actual
    def test002(self):
        username = self.list[1]["username"]
        password = self.list[1]["password"]
        expect = self.list[1]["expect"]
        ses=requests.session()
        result=ses.post(url="http://192.168.2.193:8080/woniuboss2.5/log/userLogin" ,
                 data={"userName":username,"userPass":password,"checkcode":"0000"},)
        actual=result.text
        print(actual)
        print(expect)
        assert expect == actual
    def test003(self):
        username = self.list[2]["username"]
        password = self.list[2]["password"]
        expect = self.list[2]["expect"]
        ses=requests.session()
        result=ses.post(url="http://192.168.2.193:8080/woniuboss2.5/log/userLogin" ,
                 data={"userName":username,"userPass":password,"checkcode":"0000"},)
        actual=result.text
        print(actual)
        print(expect)
        assert expect == actual

    def test004(self):
        username = self.list[3]["username"]
        password = self.list[3]["password"]
        expect = self.list[3]["expect"]
        ses = requests.session()
        result = ses.post(url="http://192.168.2.193:8080/woniuboss2.5/log/userLogin",
                          data={"userName": username, "userPass": password, "checkcode": "0000"}, )
        actual = result.text
        print(expect)
        assert expect in actual
    def test005(self):
        username = self.list[4]["username"]
        password = self.list[4]["password"]
        expect = self.list[4]["expect"]
        ses = requests.session()
        result = ses.post(url="http://192.168.2.193:8080/woniuboss2.5/log/userLogin",
                          data={"userName":username, "userPass": password, "checkcode": "0000"}, )
        actual = result.text
        print(expect)
        assert expect in actual
    def tearDown(self):
        pass
if __name__ == '__main__':
    # unittest.main()
    suite=unittest.TestSuite()
    suite.addTests(unittest.TestLoader().loadTestsFromTestCase(WoniuBoss_Login))
    with open("woniuboss_login.html","w",encoding="utf8") as file:
        runner = HTMLTestRunner(stream=file,verbosity=2,title = "测试报告",
                                description="woniuboss登陆测试报告")
        runner.run(suite)

